/********************************************************************
	filename: 	lyricwindow.h
	author:		zouyf
	created:	2009-10-24  12:16:57
	describe:

*********************************************************************/
#pragma once
#include "../resource.h"
#include "../uitls.h"
#include "custommenu.h"
#include "lyricdownloadwnd.h"

class FLyricWindow : public CWindowImpl<FLyricWindow, CWindow>,
					 public FCustomMenu<FLyricWindow>
{
public:
	BEGIN_MSG_MAP_EX(FLyricWindow)
		MSG_WM_CREATE(OnCreate)
		MSG_WM_PAINT(OnPaint)
		MSG_WM_RBUTTONDOWN(OnRButtonDown)
		MESSAGE_HANDLER_EX(WM_USER_LYCPLAY, OnPlay)
		MESSAGE_HANDLER_EX(WM_USER_LYCUPDATE, UpdateLyric)
		MESSAGE_HANDLER_EX(WM_USER_LYDOWNLOADFINISH, OnLyricDownloaded)
		MESSAGE_HANDLER_EX(WM_USER_LYRESETPOS, OnResetLyricPos)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_RESEARCH, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_ADD_100, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_ADD_500, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_ADD_1000, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_ADD_5000, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_LOW_100, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_LOW_500, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_LOW_1000, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_TIME_LOW_5000, OnClickMenuItem)
		COMMAND_ID_HANDLER_EX(IDS_LYRIC_ASSIGN, OnClickMenuItem)
	END_MSG_MAP()

	FLyricWindow() : m_bTimerRun(FALSE), m_nCurIdx(0){}
	~FLyricWindow()
	{
	}

	void Init(IApplication *pApp);
	int OnCreate(LPCREATESTRUCT lpCreateStruct);
	void OnRButtonDown(UINT nFlags, CPoint point);
	void OnClickMenuItem(UINT uNotifyCode, int nID, CWindow wndCtl);
	LRESULT OnPlay(UINT uMsg, WPARAM wParam, LPARAM lParam);
	LRESULT OnLyricDownloaded(UINT uMsg, WPARAM wParam, LPARAM lParam);
	LRESULT OnResetLyricPos(UINT uMsg, WPARAM wParam, LPARAM lParam);
	void OnPaint(CDCHandle dc);
	LRESULT UpdateLyric(UINT uMsg, WPARAM wParam, LPARAM lParam);

private:
	void DrawLyric();
	void ModifyOffset(int const& nOffset);
	void PaintText_Mid(Gdiplus::Graphics &g, Gdiplus::SolidBrush &brush, int y, LPCWSTR str);

private:
	IApplication *m_pApp;
	BOOL m_bTimerRun;
	int m_nCurIdx;
	std::vector<long> m_nVec;
	FLyricDownloadWnd	m_lyricDownloadWnd;
};
